function gradePage()
{
	
	let userId = getCookie("userId") == "" ? "0" : getCookie("userId");
	let txt = "";
	$.ajax({
		type:"post",
		url:baseUrl + "/gradePage",
		dataType:"json",
		data:
		{
			"userId" : userId
		},
		async:true,
		success:function(data)
		{
			if(data["data"]["user"] == undefined || data["data"]["user"]["type"] == 1)
			{
				if(data["data"]["list"].length == 0)
				{
					txt += `
						<div class="container">
							<table class=" table table-bordered table-striped table-hover text-center">
								<thead>
									<tr >
										<th class="text-center">序号</th>
										<th class="text-center">标题</th>
										<th class="text-center">老师</th>
										<th class="text-center">状态</th>
										<th class="text-center">得分</th>
										<th class="text-center">操作</th>
									</tr>
								</thead>
								<tbody>
									<tr>
										<td colspan="6">无数据</td>
									</tr>
								</tbody>
							</table>
						</div>
					`;
				}
				else 
				{
					txt += `
						<div class="container">
							<table class=" table table-bordered table-striped table-hover text-center">
								<thead>
									<tr >
										<th class="text-center">序号</th>
										<th class="text-center">标题</th>
										<th class="text-center">老师</th>
										<th class="text-center">状态</th>
										<th class="text-center">得分</th>
										<th class="text-center">操作</th>
									</tr>
								</thead>
								<tbody>`;
								for(let i = 0; i < data["data"]["list"].length; i++)
								{
									txt += `
										<tr>
											<td>` + (i + 1) + `</td>
											<td>` + data["data"]["list"][i]["taskTitle"] + `</td>
											<td>` + data["data"]["list"][i]["username"] + `</td>
											<td>` + (data["data"]["list"][i]["gradeNum"] == undefined ? "未提交" : (data["data"]["list"][i]["gradeNum"] == -1 ? "待批改" : "已批改")) + `</td>
											<td>` + ((data["data"]["list"][i]["gradeNum"] != undefined && data["data"]["list"][i]["gradeNum"] != -1) ? data["data"]["list"][i]["gradeNum"] : "暂无") + `</td>
											<td><a href="index.html?title=taskShow&taskId=` + data["data"]["list"][i]["taskId"] + `"><button class="btn btn-primary btn-xs">查看</button></a></td>
										</tr>
									`;
								}
								txt += `
								</tbody>
							</table>
						</div>
					`;
					
				}
			}
			else if(data["data"]["user"]["type"] == 2)
			{
				if(data["data"]["list"].length == 0)
				{
					txt += `
						<div class="container">
							<table class=" table table-bordered table-striped table-hover text-center">
								<thead>
									<tr >
										<th class="text-center">序号</th>
										<th class="text-center">标题</th>
										<th class="text-center">学生</th>
										<th class="text-center">状态</th>
										<th class="text-center">得分</th>
										<th class="text-center">操作</th>
									</tr>
								</thead>
								<tbody>
									<tr>
										<td colspan="6">无数据</td>
									</tr>
								</tbody>
							</table>
						</div>
					`;
				}
				else 
				{
					txt += `
						<div class="container">
							<table class=" table table-bordered table-striped table-hover text-center">
								<thead>
									<tr >
										<th class="text-center">序号</th>
										<th class="text-center">标题</th>
										<th class="text-center">学生</th>
										<th class="text-center">状态</th>
										<th class="text-center">得分</th>
										<th class="text-center">操作</th>
									</tr>
								</thead>
								<tbody>`;
								for(let i = 0; i < data["data"]["list"].length; i++)
								{
									txt += `
										<tr>
											<td>` + (i + 1) + `</td>
											<td>` + data["data"]["list"][i]["taskTitle"] + `</td>
											<td>` + data["data"]["list"][i]["username"] + `</td>
											<td>` + (data["data"]["list"][i]["gradeNum"] == -1 ? "待批改" : "已批改") + `</td>
											<td>` + (data["data"]["list"][i]["gradeNum"] != -1 ? data["data"]["list"][i]["gradeNum"] : "暂无") + `</td>
											<td><a href="index.html?title=gradeShow&gradeId=` + data["data"]["list"][i]["gradeId"] + `"><button class="btn btn-primary btn-xs">查看</button></a></td>
										</tr>
									`;
								}
								txt += `
								</tbody>
							</table>
						</div>
					`;
					
				}
				
				
				
			}
			else if(data["data"]["user"]["type"] == 3)
			{
				if(data["data"]["list"].length == 0)
				{
					txt += `
						<div class="container">
							<table class=" table table-bordered table-striped table-hover text-center">
								<thead>
									<tr >
										<th class="text-center">序号</th>
										<th class="text-center">标题</th>
										<th class="text-center">老师</th>
										<th class="text-center">学生</th>
										<th class="text-center">状态</th>
										<th class="text-center">得分</th>
										<th class="text-center">操作</th>
									</tr>
								</thead>
								<tbody>
									<tr>
										<td colspan="7">无数据</td>
									</tr>
								</tbody>
							</table>
						</div>
					`;
				}
				else 
				{
					txt += `
						<div class="container">
							<table class=" table table-bordered table-striped table-hover text-center">
								<thead>
									<tr >
										<th class="text-center">序号</th>
										<th class="text-center">标题</th>
										<th class="text-center">老师</th>
										<th class="text-center">学生</th>
										<th class="text-center">状态</th>
										<th class="text-center">得分</th>
										<th class="text-center">操作</th>
									</tr>
								</thead>
								<tbody>`;
								for(let i = 0; i < data["data"]["list"].length; i++)
								{
									txt += `
										<tr>
											<td>` + (i + 1) + `</td>
											<td>` + data["data"]["list"][i]["taskTitle"] + `</td>
											<td>` + data["data"]["list"][i]["teacherName"] + `</td>
											<td>` + data["data"]["list"][i]["studentName"] + `</td>
											<td>` + (data["data"]["list"][i]["gradeNum"] == -1 ? "待批改" : "已批改") + `</td>
											<td>` + (data["data"]["list"][i]["gradeNum"] != -1 ? data["data"]["list"][i]["gradeNum"] : "暂无") + `</td>
											<td><a href="index.html?title=gradeShow&gradeId=` + data["data"]["list"][i]["gradeId"] + `"><button class="btn btn-primary btn-xs">查看</button></a></td>
										</tr>
									`;
								}
								txt += `
								</tbody>
							</table>
						</div>
					`;
					
				}
				
				
			}
				
			$("body").append(txt);
			
		},
		error:function()
		{
			txt += `
				<div class="container">
					<table class=" table table-bordered table-striped table-hover text-center">
						<thead>
							<tr >
								<th class="text-center">序号</th>
								<th class="text-center">标题</th>
								<th class="text-center">老师</th>
								<th class="text-center">状态</th>
								<th class="text-center">得分</th>
								<th class="text-center">操作</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td colspan="6">无数据</td>
							</tr>
						</tbody>
					</table>
				</div>
			`;
			$("body").append(txt);
		}
		
	});
	
}


function gradeShowPage()
{
	
	let txt = "";
	let userId = getCookie("userId") == "" ? "0" : getCookie("userId");
	$.ajax({
		type:"post",
		url:baseUrl + "/gradeShowPage",
		dataType:"json",
		data:
		{
			"userId" : userId,
			"gradeId" : analyseSearch("gradeId")
		},
		async:true,
		success:function(data)
		{
			type = data["data"]["user"]["type"];
			if(type == 2)
			{
				txt += `
					<div class="container">
						<h4>标题</h4>
						<div style="margin-left: 20px;">` + data["data"]["show"]["taskTitle"] + `</div>
						<h4>主要内容</h4>
						<div style="margin-left: 20px;">` + data["data"]["show"]["taskMain"] + `</div>
						<h4>学生</h4>
						<div style="margin-left: 20px;">` + data["data"]["show"]["username"] + `</div>
						<h4>提交状态</h4>
						<div style="margin-left: 20px;">` + (data["data"]["show"]["gradeNum"] == -1 ? "待批改" : "已批改") + `</div>
						<h4>答案</h4>
						<div style="margin-left: 20px;">` + data["data"]["show"]["gradeAnswer"] + `</div>
						<h4>得分</h4>
				`;
				if(data["data"]["show"]["gradeNum"] == -1)
				{
					txt += `
						<input id="gradeNum" type="number" class="form-control"/>
						<button class="btn btn-primary" style="margin: 20px;" onclick="saveGrade()">提交</button>
					`;
				}
				else
				{
					txt += `
						<div style="margin-left: 20px;">` + data["data"]["show"]["gradeNum"] + `</div>
					`;
				}
					txt += `
					<div></div>
					<button class="btn btn-primary" onclick="history.go(-1)">返回</button>
				</div>
					`;
			}
			else if(type == 3)
			{
				txt += `
					<div class="container">
						<h4>标题</h4>
						<div style="margin-left: 20px;">` + data["data"]["show"]["taskTitle"] + `</div>
						<h4>主要内容</h4>
						<div style="margin-left: 20px;">` + data["data"]["show"]["taskMain"] + `</div>
						<h4>学生</h4>
						<div style="margin-left: 20px;">` + data["data"]["show"]["username"] + `</div>
						<h4>提交状态</h4>
						<div style="margin-left: 20px;">` + (data["data"]["show"]["gradeNum"] == -1 ? "待批改" : "已批改") + `</div>
						<h4>答案</h4>
						<div style="margin-left: 20px;">` + data["data"]["show"]["gradeAnswer"] + `</div>
						<h4>得分</h4>
						<div style="margin-left: 20px;">` + (data["data"]["show"]["gradeNum"] != -1 ? data["data"]["show"]["gradeNum"] : "暂无") + `</div>
						<button class="btn btn-primary" onclick="history.go(-1)">返回</button>
					</div>
				`;
			}
			
			$("body").append(txt);
		},
		error:function()
		{
			
			txt += `
				<div class="container">
					<h4>标题</h4>
					<div style="margin-left: 20px;">……</div>
					<h4>老师</h4>
					<div style="margin-left: 20px;">……</div>
					<h4>主要内容</h4>
					<div style="margin-left: 20px;">……</div>
					<h4>提交状态</h4>
					<div style="margin-left: 20px;">……</div>
					<h4>答案</h4>
					<div style="margin-left: 20px;">……</div>
					<h4>得分</h4>
					<div style="margin-left: 20px;">……</div>
					<button class="btn btn-primary" onclick="history.go(-1)">返回</button>
				</div>
			`;
			
			$("body").append(txt);
			
		}
	});
	
}


function saveGrade()
{
	
	let gradeNum = $("#gradeNum").val().trim();
	if(gradeNum == "")
	{
		$("#myModalBody").text("请输入完整数据！");
		$("#myModal").modal("show");
		return;
	}
	$.ajax({
		type:"post",
		url:baseUrl + "/saveGrade",
		data:
		{
			"gradeId":analyseSearch("gradeId"),
			"gradeNum":gradeNum
		},
		dataType:"json",
		success:function(data)
		{
			if(data["meta"]["status"] == 200)
			{
				window.location.assign("index.html?title=grade");
			}
			else 
			{
				$("#myModalBody").text("保存失败！");
				$("#myModal").modal("show");
			}
		},
		error:function()
		{
			$("#myModalBody").text("网络错误！");
			$("#myModal").modal("show");
		}
		
	});
	
	
}


function addNewGrade()
{
	let userId = getCookie("userId");
	if(userId == "")
	{
		$("#myModalBody").text("未登录！");
		$("#myModal").modal("show");
	}
	let gradeAnswer = $("#gradeAnswer").val().trim();
	if(gradeAnswer == "")
	{
		$("#myModalBody").text("请输入完整数据！");
		$("#myModal").modal("show");
	}
	$.ajax({
		type:"post",
		url:baseUrl + "/addNewGradeAnswer",
		data:
		{
			"userId":userId,
			"taskId":analyseSearch("taskId"),
			"gradeAnswer":gradeAnswer
		},
		dataType:"json",
		success:function(data)
		{
			if(data["meta"]["status"] == "200")
			{
				window.location.assign("index.html?title=grade");
			}
			else 
			{
				$("#myModalBody").text("保存失败！");
				$("#myModal").modal("show");
			}
		},
		error:function()
		{
			$("#myModalBody").text("网络错误！");
			$("#myModal").modal("show");
		}
		
	});
	
}
